from selenium import webdriver
from bs4 import BeautifulSoup
import random
import time
from selenium.webdriver.common.keys import Keys

# url = 'https://www.mi.com/html/index.html'
url = 'https://dianqi.suning.com/newhome3.html?safp=d488778a.homepagev8.126605638688.2&safpn=10001'

driver = webdriver.Chrome()
driver.get(url)

for i in range(20):
    driver.find_element_by_tag_name("body").send_keys(Keys.PAGE_DOWN)
    time.sleep(random.randint(1, 4))
# driver.execute_script("var q=document.body.scrollTop=0")


page = driver.page_source
with open(r'./xiaomi.html', 'w+',encoding='utf-8') as f:
    f.write(page)
driver.quit()

soup = BeautifulSoup(page, 'html.parser')
link = soup.find_all('li', {'class':'good-box cms-good'})
for i in link:
    print(i.text)

